package com.project.design.algorithm;

/**
 * 选择排序
 */
public class SelectionSort {

    public Integer[] selectionSort(Integer[] str) {
        int len = str.length;
        Integer minValue, temp;
        int count = 0;
        for (int i = 0; i < len - 1; i++) {
            minValue = i;
            for (int j = i + 1; j < len; j++) {
                if (str[minValue] > str[j]) {
                    minValue = j;
                }
                count++;
            }
            temp = str[i];
            str[i] = str[minValue];
            str[minValue] = temp;
        }
        System.out.println("循环次数：" + count);
        return str;
    }
}
